package com.hcom.controller;

import com.alibaba.fastjson2.JSON;
import com.hc.entity.NoticeArriva;
import com.hc.entity.User;
import com.hc.vo.OrderInfro;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description：
 * @Author：曹杰克
 * @CreateTime：2022/10/27 21:37
 */
@RestController
@RequestMapping("/provider")
public class UserNoticeGoodsProvider {
    @Autowired
    RabbitTemplate rabbitTemplate;
    /**
     * 生产者发送消息到交换机--exchangetopic  路由为--exchangetopic  消息体为----"email"
     * 发送发送邮件的消息
     * @return
     */
    @RequestMapping("/hasGoodsNotice")
    public String email(@RequestBody NoticeArriva noticeArriva){
        String s = JSON.toJSONString(noticeArriva);
        rabbitTemplate.convertAndSend("exchangetopic", "hasgoodsnotice", s,
                new MessagePostProcessor() {
                    @Override
                    public Message postProcessMessage(Message message) throws AmqpException {
                        //对消息对象增强，添加附件属性
                        //设置消息延迟发送的时间，安装延迟插件
                        //message.getMessageProperties().setDelay(1000);
                        //设置消息有效时间:在有效时间内，消息没有及时被消费，
                             //  有死信队列：进入死信队列
                            //  没有死信队列：消息丢失
                            // message.getMessageProperties().setExpiration("10000");
                        message.getMessageProperties().setHeader("h1", "v1");
                        message.getMessageProperties().setHeader("h2", "v2");
                        return message;
                    }
                });
        return "user";
    }


}
